<?php

namespace backend\models\user;

use Yii;

/**
 * This is the model class for table "{{%user_log}}".
 *
 * @property integer $log_id
 * @property integer $log_addtime
 * @property integer $user_id
 * @property string $log_info
 * @property string $ip_address
 * @property integer $log_type
 */
class UserLog extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%user_log}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['log_addtime', 'user_id', 'log_type'], 'integer'],
            [['log_info'], 'string', 'max' => 255],
            [['ip_address'], 'string', 'max' => 20]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'log_id' => 'Log ID',
            'log_addtime' => 'Log Addtime',
            'user_id' => 'User ID',
            'log_info' => 'Log Info',
            'ip_address' => 'Ip Address',
            'log_type' => 'Log Type',
        ];
    }

	/* 用户登录数（不含重复登录）今日 */
	static public function TodayLogin($today_start,$today_end)
	{
		return UserLog::find()
				->where("log_addtime>= :today_start and log_addtime<= :today_end and log_type = :log_type",
				[':today_start'=>$today_start,':today_end'=>$today_end,':log_type'=>1])
				->groupBy("user_id")
				->count();
	}

	/* 用户登录数（不含重复登录）昨日 */
	static public function YesterdayLogin($yesterday_start,$yesterday_end)
	{
		return UserLog::find()
				->where("log_addtime>= :yesterday_start and log_addtime<= :yesterday_end and log_type = :log_type",
				[':yesterday_start'=>$yesterday_start,':yesterday_end'=>$yesterday_end,':log_type'=>1])
				->groupBy("user_id")
				->count();
	}

	/* 视频观看数（含重复打开） 今日 */
	static public function TodaySeevideo($today_start,$today_end)
	{
		return UserLog::find()
				->where("log_addtime>= :today_start and log_addtime<= :today_end and log_type = :log_type",
				[':today_start'=>$today_start,':today_end'=>$today_end,':log_type'=>1])
				->count();
	}

	/* 视频观看数（含重复打开） 昨日 */
	static public function YesterdaySeevideo($yesterday_start,$yesterday_end)
	{
		return UserLog::find()
				->where("log_addtime>= :yesterday_start and log_addtime<= :yesterday_end and log_type = :log_type",
				[':yesterday_start'=>$yesterday_start,':yesterday_end'=>$yesterday_end,':log_type'=>1])
				->count();
	}
}
